<?php
    global $_W,$_GPC;
        function ihttpsss($url){
	        $curl = curl_init();
		    curl_setopt($curl, CURLOPT_URL, $url);
		    curl_setopt($curl, CURLOPT_HEADER, flase);
		    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
		    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
		    curl_setopt($curl, CURLOPT_TIMEOUT, 500);
		    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		    $res = curl_exec($curl);
		    curl_close($curl);   
          	return $res;       	
        }    
    if($_W['role']){
        $setting = pdo_get('mii_ang_setting',array('uniacid'=>$_W['uniacid']),array('appid','appsecret'));
        $code = $_GPC['code'];//前端传来的code值
        $appid = $setting['appid'];
        $appsecret = $setting['appsecret'];//获取openid
        $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code";
        $result = ihttpsss($url);
        $jsoninfo = json_decode($result, true);
        $openid = $jsoninfo["openid"];//从返回json结果中读出openid
        $access_token = $jsoninfo["access_token"];//从返回json结果中读出openid
        $callback=$_GPC['callback'];  // echo $callback."({result:'".$openid."'})";

        $url1 = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang=zh_CN";
        $result1 = ihttpsss($url1);
        $jsoninfo1 = json_decode($result1, true);
        $nickname=$jsoninfo1["nickname"];
        echo $openid.":".$access_token.":".$nickname; //把openid 送回前端

      }


?>
